package com.example.security_demo.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;

import javax.crypto.SecretKey;
import java.util.Date;

/**
 * 通过jjwt 创建Token
 *
 * @author zzh
 * @date 2022/5/7
 * @since 1.0
 */
public class JwtUtils {

    /**
     * 创建 Token
     * @return String token
     */
    public static String createToken() {

        SecretKey secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS256);
        return Jwts.builder().setSubject("hello").setExpiration(new Date(System.currentTimeMillis() + 60 * 1000)).signWith(secretKey).compact();
    }
}
